<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2019/1/15
 * Time: 15:25
 */
namespace app\shop\controller;
use think\Db;
class Man extends Base
{
    /**
     * 达人中心
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function manPage(){
        extract(input());
        $search = input('param.search/a');
        $page = input('param.page');
        if(!$page){
            $pages = 0;
        }else{
            $pages = $page-1;
        }
        $search = $this->search($search, $page);
        //搜索条件
        $map = [];
        $map['sup_status'] = 2;
        //任务名称
        if($search[0] != ""){
            $map['sup_name'] = ['like',"%" . $search[0] . "%"];
        }
        $data = Db::name('super s')
            ->join('u_user u','s.sup_user_id = u.user_id','left')
            ->where($map)
            ->field(['sup_id','sup_name','sup_age','sup_high','sup_goods','sup_jianjie','sup_image','photo','user_image','sup_phone'])
            ->order('sup_check_time desc')
            ->paginate(18);
        $page = $data->render();
        $data = $data->all();
        foreach ($data as $key=>$vo){
            $sup_goods = explode(',',$vo['sup_goods']);
            $data[$key]['goods']= $sup_goods;
        }
        return $this->fetch ('man/man_page',['data'=>$data,'pages'=>$pages,'page'=>$page,'search'=>$search]);
    }


    /**
     * 达人详情
     * @return mixed
     */
    public function manDetail(){
        $data = Db::name('super s')
            ->join('u_user u','s.sup_user_id = u.user_id','left')
            ->where('sup_id',input('sup_id'))
            ->field(['sup_id','user_image','sup_name','sup_age','sup_high','sup_goods','sup_jianjie','sup_image','photo'])
            ->find();
        $data['goods']= explode(',',$data['sup_goods']);
        return $this->fetch ('man/man_detail',['data'=>$data]);
    }

}